package com.utils.annotationWork;

import com.utils.annotation.IsPassword;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Objects;

public class IsPasswordValidated implements ConstraintValidator<IsPassword, String> {
    private String message;
    private boolean isRequire;

    @Override
    public void initialize(IsPassword constraintAnnotation) {
        this.message = constraintAnnotation.message();
        this.isRequire = constraintAnnotation.required();
    }

    @Override
    public boolean isValid(String o, ConstraintValidatorContext constraintValidatorContext) {
        if(Objects.nonNull(o) && isRequire) {
            //非空进行校验 {8,16}
            return true;///Pattern.matches("^(?=.*[A-Za-z])(?=.*\\d)(?=.*[`~@#$^*()\\-=[{}]\\\\|:;\"',.?/])[\\w`~@#$^*()\\-=[{}]\\\\|:;\"',.?/]", o);
        }
        return true;
    }

}
